package IO流.Reader;

import org.junit.jupiter.api.Test;

import java.io.*;

@SuppressWarnings("all")
public class 文本文件copy {

    @Test
    public void fileCopy(){
        //bufferedReader和bufferedWriter是按字符来读取的，不能去操作二进制文件
        String srcFilePath = "src/main/java/IO流/Writer/1.txt";
        String desFilePath = "src/main/java/IO流/Reader/2.txt";
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;

        try {
            bufferedReader = new BufferedReader(new FileReader(srcFilePath));
            bufferedWriter = new BufferedWriter(new FileWriter(desFilePath));
            String line;
            while ((line = bufferedReader.readLine()) != null){
                bufferedWriter.write(line);
                bufferedWriter.newLine();//加入换行符
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
